﻿using System.Windows;
using System.Windows.Controls;
using Stoplight.Interfaces;
using Microsoft.Practices.SLUnity;
using Stoplight.Events;

namespace Stoplight.Base
{
    public class PresenterBase<TView> where TView : IView
    {
        [Dependency]
        public IUnityContainer UnityContainer { get; set; }

        [Dependency]
        public ILoggerFacade Logger { get; set; }

        [Dependency]
        public IEventAggregator EventAggregator { get; set; }

        private TView _view;
        public TView View
        {
            get { return _view; }
            set
            {
                _view = value;
                OnViewSet();
            }
        }

        public void ButtonClick(object sender, RoutedEventArgs e)
        {
            Logger.Log(string.Format("{0} clicked", 
                ((Button)sender).Content), Category.Debug, Priority.None);

            OnButtonClick(
                (Button)sender, 
                new ButtonEventArgs() { TagString = ((Button)sender).Tag.ToString()}
            );
        }

        protected virtual void OnButtonClick(Button button, ButtonEventArgs e) { }
        protected virtual void OnViewSet() { }

        protected TControl FindName<TControl>(string name)
        {
            return (TControl)View.FindName(name);
        }


    }
}
